<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>删除</title>
    </head>


<body background="resourse/bg.jpg">

<%--判断是否登录--%>
<%
    String userid=(String)session.getAttribute("userid");
//    System.out.print("Session userID="+userid);

    if (userid!=null) {
%> 

<h3>UserID：<%=(String)session.getAttribute("userid")%>, 在线中..</h3>
<hr>




 <%
        request.setCharacterEncoding("UTF-8");
        String id = request.getParameter("id");

        Connection conn = null;
        Statement stat = null;
        ResultSet rs = null;

        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/talknewsdatabase";
        String user = "root";
        String password = "123456";

        conn = DriverManager.getConnection(url,user,password);
        stat = conn.createStatement();
        stat.executeUpdate("delete from info where user_id='" +userid +  "' and id = " + id + "");

        rs = stat.executeQuery("select * from user");
        if(rs.next()) {
            out.print("<script>alert('删帖成功！');</script>");
        } else{
        out.print("<script>alert('删帖失败！');</script>");
        }
        %>

    <script>alert('window.location=\'http://localhost:8080/showInfo.jsp\';')</script>

    <%
        if(rs != null){
         rs.close();
         rs = null;
        }

         if(stat != null) {
         stat.close();
         stat = null;
         }

         if(conn != null) {
         conn.close();
         conn = null;
         }
    %>


<%
    } else {
    out.print("<script>alert('未成功登录！');" +
    "window.location='http://localhost:8080/index.html';</script>");
    }
%>

  </body>

</html>


